//
//  MinutesToMidnightViewController.m
//  MinutesToMidnight
//
//  Created by Haili Ma on 10/21/09.
//  Copyright __MyCompanyName__ 2009. All rights reserved.
//

#import "MinutesToMidnightViewController.h"

@implementation MinutesToMidnightViewController



/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/


/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/



// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}


- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidLoad {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
	[countdownLabel setFont:[UIFont fontWithName:@"DBLCDTempBlack" size:128.0]];
	countdownLabel.text=@"IOAOIN6";
	[super viewDidLoad];
}


- (void)dealloc {
    [super dealloc];
}

- (void) updateLabel {
	NSDate* now = [NSDate date];
	NSCalendar *calendar = [NSCalendar currentCalendar];
	unsigned int unitFlag = NSHourCalendarUnit|NSMinuteCalendarUnit;
	NSDateComponents *comp = [calendar components:unitFlag fromDate:now];
	NSInteger iHour = [comp hour];
	NSInteger iMinute = [comp minute];
	NSInteger iSecond = [comp second];
	
	int hour = 23 -iHour;
	
	int min = 59 -iMinute;
	int sec = 59 - (iSecond%60);
	
//	int hour = 23 - [[now dateWithCalendarFormat:nil timeZone:nil] hourOfDay];
//	int min = 59 - [[now dateWithCalendarFormat:nil timeZone:nil] minuteOfHour];
//	int sec = 59 - [[now dateWithCalendarFormat:nil timeZone:nil] secondOfMinute];
	countdownLabel.text = [NSString stringWithFormat:@"%02d:%02d:%02d", hour, min,sec];
}  

@end
